<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String baseBath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>营销机会管理</title>
    <base href=<%=baseBath%>
          <%@include file="../common_css.jsp"%>
                  </head>
<body class="childrenBody">

<form class="layui-form" >
    <blockquote class="layui-elem-quote quoteBox">

        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="customerName"
                           class="layui-input
							searchVal" placeholder="客户名" />
                </div>
                <div class="layui-input-inline">
                    <select name="userId"  id="userId">
                        <option value="-1" >全部员工</option>

                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="state"  id="state">
                        <option value="-1" >全部线索状态</option>

                    </select>
                </div>
                <a class="layui-btn search_btn" data-type="reload"><i
                        class="layui-icon">&#xe615;</i> 搜索</a>
            </div>
        </form>

    </blockquote>
    <table id="saleChanceList" class="layui-table"  lay-filter="saleChances"></table>


    <script type="text/html" id="toolbarDemo">

        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-normal addNews_btn" lay-event="add">
                <i class="layui-icon">&#xe608;</i>
                添加
            </a>
        </div>
    </script>

    <!--操作-->
    <script id="saleChanceListBar" type="text/html">

        <a class="layui-btn layui-btn-xs" id="info" lay-event="info">详情</a>

        {{# if (d.orderState== 1) { }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="subsequent">支付尾款</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="unsubscribe">退订</a>
        {{# } else if(d.orderState== 2) { }}
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="ok">确认交付</a>
        {{# } else { }}

        {{# } }}

    </script>

</form>
<script type="text/javascript">
    layui.use(['table','layer'],function(){
        var layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;
        //营销机会列表展示
        var  tableIns = table.render({
            elem: '#saleChanceList',
            url : 'cusOrder/findCusOrder',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limits : [10,15,20,25],
            limit : 10,
            toolbar: "#toolbarDemo",
            id : "saleChanceListTable",
            method : 'post',
            cols : [[
                {field: "id", title:'编号',fixed:"true",width:80},
                {field:'orderId', title: '订单编号'},
                {field:'title', title: '客户姓名',width: 100,templet: function(d){
                        return d.customer.name
                    }},
                {field: 'car', title: '订单车型',align:"center",templet:function (d){
                        return d.car.series+" "+d.car.model
                    }},
                {field: 'stringOrderState', title: '订单状态',  align:'center'},
                {field: 'userName', title: '接待员工', align:'center',templet:function (d){
                        return d.customer.user.name
                    }},
                {field: 'createTime',title: '创建时间',align: 'center'},
                {title: '操作', templet:'#saleChanceListBar',fixed:"right",align:"center", minWidth:150}
            ]]
        });

        // 头工具栏事件
        table.on('toolbar(saleChances)',function (obj) {
            switch (obj.event) {
                case "add":
                    openAddOrUpdateSaleChanceDialog();
                    break;
            }
        });
        /**
         * 打开添加或更新对话框
         */
        function openAddOrUpdateSaleChanceDialog(id) {
            var title="营销机会管理-订单添加";
            var url = "/cusOrder/toOrderPage";
            layui.layer.open({
                title:title,
                type:2,
                area:["700px","400px"],
                maxmin:true,
                content:url
            })
        }

        table.on('tool(saleChances)',function (obj) {
            var layEvent =obj.event;
            if(layEvent == 'info'){
                layui.layer.open({
                    title:'订单详情',
                    type:2,
                    area:["700px","400px"],
                    maxmin:true,
                    content:"/cusOrder/toOrderPage?id="+$(this).parent().parent().siblings(":first").children().text()
                })
            }else if(layEvent == 'ok'){
                //改状态
                $.post('/cusOrder/updateOrder',{id:$(this).parent().parent().siblings(":first").children().text(),orderState:3},function (res) {
                    if(res=='success'){
                        top.layer.msg("操作成功");
                        // 刷新父页面
                        table.reload('saleChanceListTable')
                    }
                });
            }else if(layEvent == 'subsequent'){
                $.post('/cusOrder/updateOrder',{id:$(this).parent().parent().siblings(":first").children().text(),orderState:2},function (res) {
                    if(res=='success'){
                        top.layer.msg("操作成功");
                        // 刷新父页面
                        table.reload('saleChanceListTable')
                    }
                });
                //改状态
            }else if(layEvent == 'unsubscribe'){
                //退订
                var title="订单退订";
                var url = "/cancelApply/toCancelCreate?id="+$(this).parent().parent().siblings(":first").children().text();
                layui.layer.open({
                    title:title,
                    type:2,
                    area:["700px","400px"],
                    maxmin:true,
                    content:url
                })
            }



        });


    });

</script>
</body>
</html>